package com.evildog.workspace.invest.application.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.evildog.workspace.dependencies.mybatis.object.QueryConditionDTO;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import org.springframework.util.Assert;
import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.invest.application.dto.BudgetPageDTO;
import com.evildog.workspace.invest.application.dto.BudgetListDTO;
import com.evildog.workspace.invest.application.dto.BudgetDTO;
import com.evildog.workspace.invest.application.bo.BudgetBO;
import com.evildog.workspace.invest.application.bo.BudgetPageBO;
import com.evildog.workspace.invest.application.bo.BudgetListBO;
import com.evildog.workspace.invest.application.convert.BudgetConvert;
import java.util.List;
import com.evildog.workspace.invest.application.entity.Budget;
import com.evildog.workspace.invest.application.entity.BudgetPageDO;
import com.evildog.workspace.invest.application.entity.BudgetListDO;
import com.evildog.workspace.invest.application.mapper.BudgetMapper;
import com.evildog.workspace.invest.application.service.BudgetService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class BudgetServiceImpl extends ServiceImpl<BudgetMapper, Budget> implements BudgetService {

    @Override
    public PagedResult<BudgetPageBO> getPageList(PageQuery query, List<QueryConditionDTO> queryConditions, BudgetPageDTO pageDTO) {
        IPage<BudgetPageDO> page = this.baseMapper.getPageList(
                QueryConditionUtils.getPagination(query),
                queryConditions,
                pageDTO);
        return BudgetConvert.INSTANCE.convert(page);
    }

    @Override
    public List<BudgetListBO> getList(List<QueryConditionDTO> queryCondition, BudgetListDTO dto) {
        List<BudgetListDO> budgetList = this.baseMapper.getList(queryCondition, dto);
        return BudgetConvert.INSTANCE.convert(budgetList);
    }

    @Override
    public BudgetBO getDetailById(Long id) {
        Budget budget = getById(id);
        Assert.notNull(budget, "budget is null!");
        return BudgetConvert.INSTANCE.convert(budget);
    }

    @Override
    public boolean save(BudgetDTO dto){
        Budget newBudget = BudgetConvert.INSTANCE.convert(dto);
        return save(newBudget);
    }

    @Override
    public boolean updateById(Long id, BudgetDTO dto){
        Budget oldBudget = getById(id);
        Assert.notNull(oldBudget, "budget is null!");
        Budget newBudget = BudgetConvert.INSTANCE.convert(dto);
        newBudget.setId(id);
        return updateById(newBudget);
    }
}
